/*
 * MenuView.cpp
 *
 *  Created on: 01/06/2014
 *      Author: javier
 */

#include "MenuView.h"
#include "BZPView.h"

#define TEXTURE_W 2048.0f
#define TEXTURE_H 1536.0f

MenuView::MenuView(BZPView* view, SDLWindow* window) {
	this->view = view;
	this->window = window;
	std::string resDir = properties.getProperty("res_dir");
	std::string textureName = resDir + "menu.png";
	menuTexture = window->loadTexture(textureName);
	geometry.x = 0;
	geometry.y = 0;
	geometry.w = properties.getPropertyAsInt("screen.width");
	geometry.h = properties.getPropertyAsInt("screen.height");
}

MenuView::~MenuView() {
	// TODO Auto-generated destructor stub
}

void MenuView::handleClick(int x, int y) {
	int width = properties.getPropertyAsInt("screen.width");
	double widthFactor = width / TEXTURE_W;
	int height = properties.getPropertyAsInt("screen.height");
	double heightFactor = height / TEXTURE_H;
	if (x > 725 * widthFactor && x < 1400 * widthFactor) {
		if (y > 933 * heightFactor && y < 1023 * heightFactor) {
			view->newGame();
		} else if (y > 1140 * heightFactor && y < 1221 * heightFactor) {
			view->joinGame();
		} else if (y > 1308 * heightFactor && y < 1383 * heightFactor) {
			view->exit();
		}
	}
}

void MenuView::render() {
	window->renderTexture(menuTexture, &geometry);
}
